<script type="text/javascript">
var shopId = $("#shop_id").val();

$(function(){
	$("#form_community").datagrid({
		title:'可配送社区服务点列表',
		url:'/shop/findCommunity',
		queryParams: {
			shopId : shopId
		},
		columns:[[
			{field:'shopName',title:'商铺名称',width:120},
			{field:'communityName',title:'社区名称',width:120}, 
			{field:'contactsName',title:'社区联系人',width:120}, 
			{field:'contactsPhone',title:'联系人电话',width:120},
			{field:'address',title:'社区详细地址',width:120}, 
			{field:'status',title:'状态',width:50,align:'center',
	      		formatter:function(value,row,index){
		      		if(row.status==1){
		      			return "有效"
		      		} else {
		      			return "无效"
		      		}
				}
			},
			{field:'cz',title:'操作',
				formatter:function(value,row,index){
		        	return "<a onclick='deleteCommunity(" + row.id + ")' class='linkbutton' icon='icon-remove'>删除</a>";
		        }
			}
		]],
	    toolbar : [],
	    pagination:false,
	    onDblClickRow:function(rowIndex, rowData){
			$(this).datagrid('unselectAll');
			$(this).datagrid('selectRow', rowIndex);
		},
	    onLoadSuccess:function(data){
			$(".linkbutton").linkbutton();
		}
	});
	
	$("#community_id").combobox({    
	    url: '/community/combobox',   
	    valueField:'id',    
	    textField:'name',
	    required: true,
	    width:122
	}); 
});

function deleteCommunity(id){
	$.ajax({
		url: "/shop/deleteCommunity",
		data: {"id":id},
			dataType: "json",
			success : function(r) {
			if (r.success) {
				$("#form_community").datagrid('load');
				$("#form_community").datagrid('unselectAll');
				$.messager.show({
					msg:r.msg,
					title:'提示'
				});
				editRow = undefined;
			} else {
				$.messager.alert("操作错误",r.msg,'error');
			}
		}
	});
}

function submitCommunity() {
	var shop_id = $("#shop_id").val();
	var community_id = $("#community_id").combobox('getValue');
	
	$.ajax({
		url: "/shop/savaCommunity",
		data: {"shopId":shop_id,"communityId":community_id},
			dataType: "json",
			success : function(r) {
			if (r.success) {
				$("#form_community").datagrid('load');
				$("#form_community").datagrid('unselectAll');
				$.messager.show({
					msg:r.msg,
					title:'提示'
				});
				editRow = undefined;
			} else {
				$.messager.alert("操作错误",r.msg,'error');
			}
		}
	});
}
</script>
<div title="社区服务点" style="padding:5px;">
	<input id="shop_id" type="hidden" name="shop_id"  value="${(po.id)!}"/>
	<table class="tableForm tableCss" id="project_income_table">
		<tr>
				<th><font color=red>*</font>商铺名称</th>
				<td>${(po.name)!}</td>
				<th><font color=red>*</font>选择社区服务点</th>
				<td><input id="community_id" name="community_id" value=""/></td>
			</tr>
				<td colspan="4" align="center">
					<a onclick="javascript:submitCommunity();" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>
				</td>
			</tr>
		</tr>
	</table>
	<table id="form_community"></table> 
</div>